package com.example.lancooznbk.view.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.example.lancooznbk.R;

import znbkListBj.activity.NotesListActivity;
import znbkListCtfd.activity.WrongTopicTutoringListActivity;
import znbkListNtxl.activity.TrainingDifficultProblemsListActivity;
import znbkListRdqh.activity.WeekAscensionListActivity;
import znbkListRdtz.activity.HeatPointExtensionListActivity;
import znbkListSc.activity.CollectionListActivity;
import znbkListXtfx.activity.SystemReviewListActivity;

/**
 * Created by Administrator on 2018\1\26 0026.
 */


public class HeaderBottomAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    //item类型
    public static final int ITEM_TYPE_HEADER = 0;
    public static final int ITEM_TYPE_CONTENT = 1;
    public static final int ITEM_TYPE_BOTTOM = 2;
    //模拟数据
    public String [] texts={"java","python","C++","Php",".NET"};
    private LayoutInflater mLayoutInflater;
    private static Context mContext;
    private int mHeaderCount=1;//头部View个数
    private int mBottomCount=1;//底部View个数
    public HeaderBottomAdapter(Context context) {
        mContext = context;
        mLayoutInflater = LayoutInflater.from(context);
    }
    //内容长度
    public int getContentItemCount(){
        return texts.length;
    }
    //判断当前item是否是HeadView
    public boolean isHeaderView(int position) {
        return mHeaderCount != 0 && position < mHeaderCount;
    }
    //判断当前item是否是FooterView
    public boolean isBottomView(int position) {
        return mBottomCount != 0 && position >= (mHeaderCount + getContentItemCount());
    }
    //判断当前item类型
    @Override
    public int getItemViewType(int position) {
        int dataItemCount = getContentItemCount();
        if (mHeaderCount != 0 && position < mHeaderCount) {
//头部View
            return ITEM_TYPE_HEADER;
        } else if (mBottomCount != 0 && position >= (mHeaderCount + dataItemCount)) {
//底部View
            return ITEM_TYPE_BOTTOM;
        } else {
//内容View
            return ITEM_TYPE_CONTENT;
        }
    }
    //内容 ViewHolder
    public static class ContentViewHolder extends RecyclerView.ViewHolder {
//        private TextView textView;
        public ContentViewHolder(View itemView) {
            super(itemView);
//            textView=(TextView)itemView.findViewById(R.id.tv_item_text);
        }
    }


    //头部 ViewHolder
    public static class HeaderViewHolder extends RecyclerView.ViewHolder {
        public HeaderViewHolder(View itemView) {
            super(itemView);
            /*
           * 主界面学习模块按钮
           * 系统复习
           * */
            LinearLayout mLayoutSystemReview;
            mLayoutSystemReview = (LinearLayout) itemView.findViewById(R.id.layout_system_review);
            mLayoutSystemReview.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(mContext, SystemReviewListActivity.class);
                    mContext.startActivity(intent);
                }
            });

            /*
           * 主界面学习模块按钮
           * 弱点强化
           * */
            LinearLayout mLayoutWeekAscension;
            mLayoutWeekAscension = (LinearLayout) itemView.findViewById(R.id.layout_week_ascension);
            mLayoutWeekAscension.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(mContext, WeekAscensionListActivity.class);
                    mContext.startActivity(intent);
                }
            });

             /*
           * 主界面学习模块按钮
           * 难题训练
           * */
            LinearLayout mLayoutTrainingDifficultProblems;
            mLayoutTrainingDifficultProblems = (LinearLayout) itemView.findViewById(R.id.layout_training_difficult_problems);
            mLayoutTrainingDifficultProblems.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(mContext, TrainingDifficultProblemsListActivity.class);
                    mContext.startActivity(intent);
                }
            });

            /*
           * 主界面学习模块按钮
           * 错题辅导
           * */
            LinearLayout mLayoutHeatPointExtension;
            mLayoutHeatPointExtension = (LinearLayout) itemView.findViewById(R.id.layout_heat_point_extension);
            mLayoutHeatPointExtension.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(mContext, HeatPointExtensionListActivity.class);
                    mContext.startActivity(intent);
                }
            });

            /*
           * 主界面学习模块按钮
           * 错题辅导
           * */
            LinearLayout mLayoutWrongTopicTutoring;
            mLayoutWrongTopicTutoring = (LinearLayout) itemView.findViewById(R.id.layout_wrong_topic_tutoring);
            mLayoutWrongTopicTutoring.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(mContext, WrongTopicTutoringListActivity.class);
                    mContext.startActivity(intent);
                }
            });

        }
    }
    //底部 ViewHolder
    public static class BottomViewHolder extends RecyclerView.ViewHolder {
        public BottomViewHolder(View itemView) {
            super(itemView);


              /*
           * 主界面学习模块按钮
           * 笔记列表
           * */
            LinearLayout mLayoutNotes;
            mLayoutNotes = (LinearLayout) itemView.findViewById(R.id.layout_notes);
            mLayoutNotes.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(mContext, NotesListActivity.class);
                    mContext.startActivity(intent);
                }
            });

            /*
           * 主界面学习模块按钮
           * 收藏列表
           * */
            LinearLayout mLayoutCollection;
            mLayoutCollection = (LinearLayout) itemView.findViewById(R.id.layout_collection);
            mLayoutCollection.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(mContext, CollectionListActivity.class);
                    mContext.startActivity(intent);
                }
            });


        }

    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType ==ITEM_TYPE_HEADER) {

//            View view = mLayoutInflater.inflate(R.layout.rv_header, parent,false);
//            return new HeaderViewHolder(view);
            return new HeaderViewHolder(mLayoutInflater.inflate(R.layout.rv_header, parent, false));
        } else if (viewType == ITEM_TYPE_CONTENT) {
            return new ContentViewHolder(mLayoutInflater.inflate(R.layout.item_rv_zjxx, parent, false));
        } else if (viewType == ITEM_TYPE_BOTTOM) {
            return new BottomViewHolder(mLayoutInflater.inflate(R.layout.rv_footer, parent, false));
        }
        return null;
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof HeaderViewHolder) {
        } else if (holder instanceof ContentViewHolder) {
//            ((ContentViewHolder) holder).textView.setText(texts[position - mHeaderCount]);
        } else if (holder instanceof BottomViewHolder) {
        }
    }
    @Override
    public int getItemCount() {
        return mHeaderCount + getContentItemCount() + mBottomCount;
    }

}